<?php
//商品栏目控制器
class CategoryControl extends Control{
	//栏目列表默认显示的首页
	public function index(){
		 $catagoryData=cache("category");
		$this->assign("data",$catagoryData);
		$this->display();
	}
  
	//添加栏目
	public function add(){
		if(IS_POST){
		$model=K("Category");
		 if($model->addCategory()){
                            $this->success("添加成功。。。",U("index"));
		 }else{
		 	$this->error($model->error);
		 }
		}else{
	              $goodsType=cache("goodsType");
	              // p($goodsType);die;
	              $this->assign("goodsType",$goodsType);
		     $this->display();	
		}
	}

	//更新缓存
	public function updatacache(){
                  $model=K("Category");
                  if($model->updataCategory()){
                   $this->success();
                  }else{
                  	 $this->error($model->error);
                  }
	}
	//编辑栏目
	public function edit(){
		if(IS_POST){
                          $model=K("category");
                          if($model->edit()){
                          	$this->success("操作成功",U("index"));
                          }else{
                          	$this->error($model->error);
                          }
		}else{
			$cid=Q("cid",0,'intval');
			$catagoryData=cache("category");
			if($cid){
			      foreach($catagoryData as $k=>$cat){
				 $disabled=$selected="";
				 //让当前栏目和子栏目禁用
				   if($cat['cid']==$catagoryData[$cid]["pid"]){//当前栏目的父级栏目选中
				   	$selected="selected=''";
				       }
				   if($cat["cid"]==$cid){//让当前栏目禁用
				   	$disabled="disabled=''";
				   }
				   if(Data::isChild($catagoryData,$cat['cid'],$cid)){
				   	$disabled="disabled=''";
				   };
				   $catagoryData[$k]['selected']=$selected;
				   $catagoryData[$k]['disabled']=$disabled;
			          }
			}
                            $this->assign("catagoryData",$catagoryData);
			$this->assign("filed",$catagoryData[$cid]);
			$this->display();
		}
	}
	//删除数据
	public function del(){
		$model=K("category");
		if($model->delCategory()){
			$this->success("删除成功...",U("index"));
		}else{
			$this->error($model->error);
		}
	}
}






